#include <stdio.h>
#include <stdlib.h>
#include "../include/constants.h"
#include "view.h"

// 定义语言选项
typedef enum {
        LANG_CN,
        LANG_EN
} language_t;

// 定义当前语言
static language_t current_language = LANG_CN;

// 清屏函数
void clear_screen()
{
#if defined(_WIN32) || defined(_WIN64)
        system("cls");  // Windows
#else
        system("clear"); // Unix/Linux/MacOS
#endif
}

// 显示菜单的通用函数
static void show_menu(const char *menu_cn, const char *menu_en)
{
        printf("%s", (current_language == LANG_CN) ? menu_cn : menu_en);
}

// 显示主菜单
static void show_main_menu()
{
        show_menu(CN_MENU, EN_MENU);
}

// 显示语言选择菜单
static void show_language_menu()
{
        clear_screen();
        show_menu(CN_LANGUAGE_MENU, EN_LANGUAGE_MENU);
}

// 切换语言
static void switch_language()
{
        int choice;
        while (1) {
                show_language_menu();
                scanf("%d", &choice);

                switch (choice) {
                        case 1: current_language = LANG_CN; return;
                        case 2: current_language = LANG_EN; return;
                        default: printf("%s", INVALID_CHOICE_CN); break;
                }
        }
}

int run_view(void)
{
        int choice;

        while (1) {
                show_main_menu();
                scanf("%d", &choice);

                switch (choice) {
                        case 1: student_view(); break;
                        case 6: switch_language(); break;
                        case 7: return 0;
                        default: clear_screen();
                                printf("%s", INVALID_CHOICE_CN); break;
                }
        }

        return 0;
}
